package com.abe.mvp.view.activity.base;

import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;

import com.abe.app.AdaptiveActivity;

/**
 * @see 本地广播集成
 * */
public abstract class BaseBroadcastActivity extends AdaptiveActivity {
	/** 广播实例 */
	public BroadcastReceiver receiveBroadCast;
	public String Action;

	/** 设置广播过滤 
	 * @return */
	public abstract void setFilterAction() ;

	@Override
	public void onResume() {
		super.onResume();
		/** 注册本地广播 */
		initLocalBroadcastManager();
	}

	@Override
	protected void onPause() {
		super.onPause();
		/** 取消注册广播 */
		LocalBroadcastManager.getInstance(this).unregisterReceiver(
				receiveBroadCast);
	}

	private void initLocalBroadcastManager() {
		setFilterAction();
		initBroadcastReceiver();
		IntentFilter filter = new IntentFilter();
		/** 只有持有相同的action的接受者才能接收此广播 */
		filter.addAction(Action);
		/** 注册应用内广播接收器 */
		LocalBroadcastManager.getInstance(this).registerReceiver(
				receiveBroadCast, filter);
	}

	/** 初始化广播接收器 */
	public abstract void initBroadcastReceiver();

}
